package com.lanou3g.code0418.control;

/**
 * If there are no bugs, it was created by Chen FengYao on 2018/4/18;
 * Otherwise, I don't know who created it either
 */

public class Test02 {
    public static int sum = 0;
    public static void main(String[] args) {
        Thread a = new Thread(new Runnable() {
            @Override
            public void run() {

                for (int i = 0; i < 10; i++) {
                    System.out.println(i + Thread.currentThread().getName());
                    sum += i;
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("子线程执行完了");
            }
        });

        a.start();

        try {
            Thread.sleep(15000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        try {
            // 调用线程对象的join方法
            // 可以让 当前线程 等待 线程对象执行完毕后
            // 再继续执行
            // 在哪个线程中调用的 线程对象.join()
            // 哪个线程就去等
            a.join();

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("主线程执行完毕" + sum);
    }

    //55
    //15 + 40 = 55

}
